package com.yunchao.feature.base.domain.result

import kotlinx.coroutines.TimeoutCancellationException
import org.json.JSONException
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.util.concurrent.TimeoutException
import kotlin.toString


class BaseException(message: String?) : Exception(message)

fun createException(message: String?): BaseException = BaseException(message)

val Throwable.errorMsg: String
    get() = when (this) {
        is UnknownHostException -> "网络连接不可用，请稍后重试！" //网络异常
        is SocketTimeoutException, is TimeoutException, is TimeoutCancellationException -> "连接超时,请稍后再试"
        is ConnectException -> "网络不给力，请稍候重试！"
        is JSONException -> "数据解析失败,请检查数据是否正确" //请求成功，但Json语法异常,导致解析失败
        else -> message ?: this.toString()
    }